define(['jquery', 'bootstrap', 'utilback', 'table', 'form'], function ($, undefined, Utilback, Table, Form) {

    var Controller = {
    	config: {
    		get_url: '/order/read/detail',
    	},
        init: function () {
            // 初始化表格参数配置
            Table.api.init({
            	singleSelect: true,
                extend: {
                    index_url: '/order/read/list',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'member.phone', title: '会员手机号'},
                        {field: 'orderNo', title: __('订单号')},
                        {field: 'orderNo', title: __('商品信息'), formatter: function (value, row, index) {
                        	var n = '';
                        	$.each(row.skuList, function(i, s) {
                        		n += s.goodsName;
                        	});
                        	return n;
                        }},
                        {field: 'fee.goodsMoney', title: __('金额')},
                        {field: 'payOrderId', title: __('支付订单')},
                        {field: 'payType', title: __('支付渠道'), formatter: function (value, row, index) {
                        	return value == '1' ? '微信' : value == '2' ? '支付宝' : value == '4' ? '小程序' : '-';
                        }},
                        {field: 'state', title: __('订单状态'), formatter: function (value, row, index) {
                        	switch(value) {
	                      	  case '1':
	                      		  return '<span class="label label-info">待付款</span>';
	                      	  case '2':
	                      		  return '<span class="label label-info">已取消</span>';
	                      	  case '3':
	                      		  return '<span class="label label-info">已完成</span>';
	                      	  case '4':
	                      		  return '<span class="label label-info">已完成</span>';
	                      	  case '5':
	                      		  return '<span class="label label-info">待评价</span>';
	                      	  case '6':
	                      		  return '<span class="label label-info">已评价</span>';
	                      	}
          	              	return '<span class="label label-info">'+value+'</span>';
                        }},
                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                             return Table.api.formatter.operate.call(this, value, row, index, table);
                        }}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            
            function refreshNotice() {
            	$('.btn-refresh').click();
            }
            setInterval(refreshNotice, 30000);
        },
        edit: function () {
            
        }
    };
    return Controller;
});